package com.atguigu.yygh.user.service.impl;

import com.atguigu.yygh.cmn.client.DictFeignClient;
import com.atguigu.yygh.model.user.Patient;
import com.atguigu.yygh.user.mapper.PatientMapper;
import com.atguigu.yygh.user.service.PatientService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 就诊人表 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2022-10-05
 */
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {

    @Autowired
    private DictFeignClient dictFeignClient;

    @Override
    public List<Patient> selectListByUserId(Long userId) {
        QueryWrapper<Patient> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        List<Patient> list = baseMapper.selectList(queryWrapper);
        for (Patient patient : list) {
            String certificatesType = patient.getCertificatesType();
            String value = dictFeignClient.getNameByValue(certificatesType);
            patient.getParam().put("certificatesTypeString",value);
            patient.getParam().put("fullAddress",dictFeignClient.getNameByValue(patient.getProvinceCode()) +
                    dictFeignClient.getNameByValue(patient.getCityCode()) +
                    dictFeignClient.getNameByValue(patient.getDistrictCode()) +
                    patient.getAddress());
        }
        return list;
    }

    @Override
    public Patient selectById(Long id) {
        Patient patient = baseMapper.selectById(id);
        String provinceString = dictFeignClient.getNameByValue(patient.getProvinceCode());
        String cityString = dictFeignClient.getNameByValue(patient.getCityCode());
        String districtString = dictFeignClient.getNameByValue(patient.getDistrictCode());
        patient.getParam().put("provinceString",provinceString);
        patient.getParam().put("cityString",cityString);
        patient.getParam().put("districtString",districtString);
        String certificatesTypeString = dictFeignClient.getNameByValue(patient.getCertificatesType());
        patient.getParam().put("certificatesTypeString",certificatesTypeString);
        return patient;
    }
}
